package servlet;

import bean.Login;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

@WebServlet(name = "adminDelete", value = "/adminDelete")
public class adminDelete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String RoomID=request.getParameter("roomID");
        System.out.println(RoomID);
        String hotelID;
        HttpSession session=request.getSession(true);
        Login login=null;
        try {
            login= (Login) session.getAttribute("ad_login");
        }catch (Exception e){}
        hotelID=login.getLoginID();
        String deletesql = "delete from rooms where RoomID="+RoomID;
        System.out.println("sql");

        try {
            Class.forName("org.mariadb.jdbc.Driver");
            Connection conn= DriverManager.getConnection("jdbc:mariadb://localhost:3306/hotel-management-system","root","123456");
            Statement statement=conn.createStatement();

            System.out.println(deletesql);

            int ret = statement.executeUpdate(deletesql);
            System.out.println(ret);
            statement.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        response.sendRedirect("admin-equry.jsp?hotelID=hotelID");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
